<?php

namespace app\admin\controller;

use app\admin\model\ScoreModel;
use cmf\controller\AdminBaseController;
use mindplay\annotations\standard\ParamAnnotation;
use think\Db;
use think\db\Query;
use think\Request;

class ScoreController extends AdminBaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $name = $this->request->param('name');
        $score = Db::name('score')
            ->where(function (Query $query)use($name){
                if ($name){
                    $query ->where('cmf_score.name','like',"%$name%");
                }
            })
            ->order('id desc')
            ->paginate('3');
       $page = $score->render();
        return view('index',['score'=>$score,'page'=>$page]);
    }
    public function add(){
        if (request()->isPost()){
            $data = input();
            $add = Db::name('score')->insert($data);
            if($add){
                $this->success('添加成功','score/index');
                $this->error('添加失败');
            }
        }
        return view('add');
    }
    public function edit(){
        if (request()->isPost()){
            $data = input();
            $edit = Db::name('score')->update($data);
            if ($edit){
                $this->success('修改成功','score/index');
                $this->error('修改失败');
            }
        }
        $id = input('id');
        $score = Db::name('score')->get($id);
        return view('edit',['score'=>$score]);
    }
    public function delete($id)
    {
        $del = Db::name('score')->delete($id);
        if ($del){
            $this->success('删除成功','score/index');
            $this->error('删除失败');
        }
    }
}
